<?php
/**
 * 奴隶
 * 
 * Created	: 2011-10-15
 * Modified : 2011-10-15
 * @author  : 陈立强
 */
class Thrall
{
	
	public static $cfg  = null;
	public static $cfgName = 'item/thrall';
	
	/**
	 * 雇佣奴隶
	 * @param id $uid
	 * @param id $to_uid 雇佣的目标玩家
	 */
	public static function employ($uid, $to_uid) 
	{
		global $DB, $G, $L;
		
		$sql = 'SELECT id FROM thrall WHERE employer_uid_id='.$uid;
		$had = $DB->getValue($sql);
		// 已经有奴隶
		if ($had) {
			return array(
				'val' => false,
				'msg' => $L['user_had_thrall']
			);
		}
		
		$sql = 'SELECT employer_uid_id FROM thrall WHERE uid='.$uid;
		$exist = $DB->getValue($sql);
		// 不能雇佣雇主
		if ($exist && $exist==$to_uid) {
			return array(
				'val' => false,
				'msg' => $L['user_had_thrall']
			);
		}
		
		$sql = 'SELECT * FROM thrall WHERE to_uid='.$to_uid;
		$exist = $DB->getValue($sql);
		// 不能雇佣雇主
		if ($exist && $exist==$to_uid) {
			return array(
				'val' => false,
				'msg' => $L['user_had_thrall']
			);
		}
		
	}
}










